using Avalonia;
using Avalonia.Controls;
using Avalonia.Media;

namespace SerialTool.Controls;

public partial class ToastNotification : UserControl
{
    public static readonly StyledProperty<string> TitleProperty = 
        AvaloniaProperty.Register<ToastNotification, string>(nameof(Title));

    public static readonly StyledProperty<string> MessageProperty = 
        AvaloniaProperty.Register<ToastNotification, string>(nameof(Message));

    public static readonly StyledProperty<string> IconProperty = 
        AvaloniaProperty.Register<ToastNotification, string>(nameof(Icon), "ℹ️");

    public static readonly StyledProperty<IBrush> IconColorProperty = 
        AvaloniaProperty.Register<ToastNotification, IBrush>(nameof(IconColor), Brushes.SkyBlue);

    public string Title
    {
        get => GetValue(TitleProperty);
        set => SetValue(TitleProperty, value);
    }

    public string Message
    {
        get => GetValue(MessageProperty);
        set => SetValue(MessageProperty, value);
    }

    public string Icon
    {
        get => GetValue(IconProperty);
        set
        {
            SetValue(IconProperty, value);
            if (this.FindControl<TextBlock>("IconText") is TextBlock iconText)
            {
                iconText.Text = value;
            }
        }
    }

    public IBrush IconColor
    {
        get => GetValue(IconColorProperty);
        set => SetValue(IconColorProperty, value);
    }

    public ToastNotification()
    {
        InitializeComponent();
        
        this.PropertyChanged += (sender, e) =>
        {
            if (e.Property == IconProperty)
            {
                if (this.FindControl<TextBlock>("IconText") is TextBlock iconText)
                {
                    iconText.Text = Icon;
                }
            }
        };
    }
} 